package com.hd.trans.files.sort;


import com.hd.trans.files.bean.Audio;
import com.hd.trans.files.bean.Video;
import com.hd.trans.files.model.FileSortModel;

import java.util.List;

/**
 * Author: yangtianwen
 * Time: 2021/12/27
 * Des:
 */
public class MediaSortHelper {

    private MediaSortHelper() {
    }

    private static class Holder {
        public static final MediaSortHelper INSTANCE = new MediaSortHelper();
    }

    public static MediaSortHelper getInstance() {
        return Holder.INSTANCE;
    }

    /**
     * 对音频进行排序
     */
    public List<Audio> sortAudio(List<Audio> audios, FileSortModel.ModeItem sortModeItem) {
        if (sortModeItem != null && sortModeItem.getMethod() != null) {
            return sortAudio(audios, sortModeItem.getMethod());
        }
        return sortAudio(audios, ISort.SortMethod.changeTimeNew2Old);
    }

    /**
     * 对音频进行排序
     */
    public List<Audio> sortAudio(List<Audio> audios, ISort.SortMethod method) {
        switch (method) {
            case createTimeNew2Old:
                return new MediaSortImpl<Audio>().orderCreateTimeNewToOld(audios);
            case createTimeOld2New:
                return new MediaSortImpl<Audio>().orderCreateTimeOldToNew(audios);
            case changeTimeNew2Old:
                return new MediaSortImpl<Audio>().orderChangeTimeNewToOld(audios);
            case changeTimeOld2New:
                return new MediaSortImpl<Audio>().orderChangeTimeOldToNew(audios);
            case sizeSmall2Big:
                return new MediaSortImpl<Audio>().orderSizeSmallToLarge(audios);
            case sizeBig2Small:
                return new MediaSortImpl<Audio>().orderSizeLargeToSmall(audios);
            case nameA2Z:
                return new MediaSortImpl<Audio>().orderNameAToZ(audios);
            case nameZ2A:
                return new MediaSortImpl<Audio>().orderNameZToA(audios);
        }
        return audios;
    }

    /**
     * 对音频进行排序
     */
    public List<Video> sortVideo(List<Video> videos, FileSortModel.ModeItem sortModeItem) {
        if (sortModeItem != null && sortModeItem.getMethod() != null) {
            return sortVideo(videos, sortModeItem.getMethod());
        }
        return sortVideo(videos, ISort.SortMethod.changeTimeNew2Old);
    }

    /**
     * 对视频进行排序
     */
    public List<Video> sortVideo(List<Video> videos, ISort.SortMethod method) {
        switch (method) {
            case createTimeNew2Old:
                return new MediaSortImpl<Video>().orderCreateTimeNewToOld(videos);
            case createTimeOld2New:
                return new MediaSortImpl<Video>().orderCreateTimeOldToNew(videos);
            case changeTimeNew2Old:
                return new MediaSortImpl<Video>().orderChangeTimeNewToOld(videos);
            case changeTimeOld2New:
                return new MediaSortImpl<Video>().orderChangeTimeOldToNew(videos);
            case sizeSmall2Big:
                return new MediaSortImpl<Video>().orderSizeSmallToLarge(videos);
            case sizeBig2Small:
                return new MediaSortImpl<Video>().orderSizeLargeToSmall(videos);
            case nameA2Z:
                return new MediaSortImpl<Video>().orderNameAToZ(videos);
            case nameZ2A:
                return new MediaSortImpl<Video>().orderNameZToA(videos);
        }
        return videos;
    }
}
